home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / crit / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-05-23  |  3.7 KB  |  162 lines  |  [TEXT/????]

  1. /*
  2.  * menu.c - menu handling.
  3.  */
  4.  
  5. #include <quickdraw.h>
  6. #include <memory.h>
  7. #include <window.h>
  8. #include <menu.h>
  9. #include <desk.h>
  10. #include <toolutil.h>
  11. #include <packages.h>
  12.  
  13. #include "critic.h"
  14.  
  15. #define DATA
  16. #include "items.h"
  17. #undef DATA
  18.  
  19. #define DLGABOUT 256    /* ResId of our "About..." dialog    */
  20.  
  21. /*
  22.  * menu_init() - Initialize the menus and desk accessories (drivers).
  23.  */
  24.  
  25. menu_init()
  26. {
  27.     int i;            /* current menu number            */
  28.     short theitem;        /* the current item in a menu        */
  29.     char name[64];        /* the name of a Font            */
  30.  
  31.     /*
  32.      * Get each of our menus from the resources,
  33.      * add all desk accessories to the Apple menu,
  34.      * Then install the menus in the menu bar.
  35.      */
  36.  
  37.     for (i = 1; i <= LASTMENU; i++) {
  38.     mymenus[i] = GetMenu(i);
  39.     }
  40.     AddResMenu(mymenus[APPLEMENU], 'DRVR');
  41.     
  42.     for (i = 1; i <= LASTMENU; i++) {
  43.     InsertMenu(mymenus[i], 0);        /* put menus at end    */
  44.     }
  45.     DrawMenuBar();
  46. }
  47.  
  48. /*
  49.  * docommand() - handle a command given through a menu selection.
  50.  *
  51.  * If the command is Quit, we return true, else false.
  52.  * Since the menu was highlighted by MenuSelect, we must finish
  53.  * by unhighlighting it to indicate we're done.
  54.  */
  55.  
  56. int    /* "the command was 'quit' */
  57. docommand(mresult)
  58. long    mresult;    /* the command to execute (a menu item)    */
  59. {
  60.     GrafPtr saveport;
  61.     int themenu;        /* the chosen menu            */
  62.     int theitem;        /* the chosen item            */
  63.     WindowPtr thewindow;    /* the active window            */
  64.     char name[64];        /* the name of a DA             */
  65.     int     returns;        /* result to return            */
  66.  
  67.     returns = 0;        /* assume Quit not selected        */
  68.     themenu = HiWord(mresult);    /* get the menu selected        */
  69.     theitem = LoWord(mresult);    /* ... and the item of that menu     */
  70.     thewindow = FrontWindow();
  71.     switch (themenu) {
  72.     case 0:         /* no selection -- do nothing */
  73.         break;
  74.  
  75.     case APPLEMENU:
  76.         switch (theitem) {
  77.         case AP_ABOUT:        /* Tell about the program    */
  78.         saydialog(DLGABOUT);
  79.             break;
  80.         default:            /* Run the selected Desk Accessory    */
  81.         GetPort(&saveport);
  82.         GetItem(mymenus[APPLEMENU], theitem, name);
  83.         (void) OpenDeskAcc(name);
  84.         SetPort(saveport);
  85.             break;
  86.         }
  87.         break;
  88.  
  89.     case FILEMENU:
  90.         switch (theitem) {
  91.         case IQUIT:            /* Quit the program            */
  92.          returns = 1;
  93.         break;
  94.         }
  95.         break;
  96.  
  97.     case EDITMENU:
  98.         switch (theitem) {
  99.         case UNDOEDIT:
  100.         case CUTEDIT:
  101.         case COPYEDIT:
  102.         case PASTEEDIT:
  103.         case CLEAREDIT:
  104.         if (thewindow == windoc) {    /* our window        */
  105.             /* if we could do edit operations, we'd do them here */
  106.         } else {            /* a DA's window    */
  107.             SystemEdit(theitem - 1);
  108.         }
  109.             break;
  110.         }
  111.         break;
  112.  
  113.     case VOICEMENU:
  114.         switch (theitem) {
  115.         case VO_SETUP:
  116.         setupvoice();
  117.             break;
  118.         }
  119.         break;
  120.     }
  121.     HiliteMenu(0);    /* we're done -- turn off the highlighting */
  122.     return(returns);
  123. }
  124.  
  125. /*
  126.  * markmenus() - take care of checking and dimming all items in all menus.
  127.  * This routine should be the only one that fiddles with menu item
  128.  * checking and dimming.
  129.  */
  130.  
  131. markmenus(whichwindow)
  132. WindowPtr whichwindow;        /* the active window            */
  133. {
  134.     MenuHandle themenu;
  135.     char txt[64];    /* (pascal) menu item text        */
  136.     
  137.     /* Apple menu is O.K.    */
  138.     /* File menu is O.K.    */
  139.  
  140.     /*
  141.      * Edit menu: dim it if our window is active.
  142.      * Otherwise, light it.
  143.      */
  144.  
  145.     themenu = mymenus[EDITMENU];
  146.     if (whichwindow == windoc) {
  147.         DisableItem(themenu, UNDOEDIT);
  148.         DisableItem(themenu, CUTEDIT);
  149.         DisableItem(themenu, COPYEDIT);
  150.         DisableItem(themenu, PASTEEDIT);
  151.         DisableItem(themenu, CLEAREDIT);
  152.     } else {
  153.         EnableItem(themenu, UNDOEDIT);
  154.         EnableItem(themenu, CUTEDIT);
  155.         EnableItem(themenu, COPYEDIT);
  156.         EnableItem(themenu, PASTEEDIT);
  157.         EnableItem(themenu, CLEAREDIT);
  158.     }
  159.  
  160.     /* Voice menu is O.K.    */
  161. }
  162.